<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
        <li class="fa fa-remove"></li>
    </button>
    <h5 class="modal-title"></h5>
</div>

<div class="modal-body">
    <form id="train_form" name="train_form" class="form-horizontal">
        <input type="hidden" name="id">
        <input type="hidden" name="version">
        <input type="hidden" name="createDateTime" data-flag="date" data-format="yyyy-mm-dd hh:ii:ss">
        <input type="hidden" name="deleted" value="0">
        <input type='hidden' value="${CSRFToken}" id='csrftoken'>
        <input type="hidden" name="state">
        <div class="box-body">
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">课程名称<span style="color:red">*</span></label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="name" name="name" placeholder="请填写课程名称">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">上课时间<span style="color:red">*</span></label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="courseTime" name="courseTime" placeholder="请填写上课时间">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">课时<span style="color:red">*</span></label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="duration" name="duration" placeholder="请填写课时">
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">上课老师<span style="color:red">*</span></label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="teacher" name="teacher" placeholder="请填写上课老师">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">地点<span style="color:red">*</span></label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="address" name="address" placeholder="请填写地点">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">备注</label>
                    <div class="col-sm-8">
                        <textarea name="remark" id="remark" placeholder="请填写备注" class="form-control"></textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-footer text-right">
            <button type="button" class="btn btn-default" data-btn-type="cancel" data-dismiss="modal">取消</button>
            <button type="submit" class="btn btn-primary" data-btn-type="save">保存</button>
        </div>
    </form>
</div>
<script>
    var trainform;
    var id = "${id?default(0)}";
    $(function () {
        //初始化表单
        trainform = $("#train_form").form();
        //数据校验
        $("#train_form").bootstrapValidator({
            message: '请输入有效值',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            submitHandler: function () {
                modals.confirm('确认保存？', function () {
                    var train = trainform.getFormSimpleData();
                    ajaxPost(basePath + '/train/save', train, function (data) {
                        if (data.success) {
                            if (id != "0") {
                                modals.hideWin(winId);
                                trainTable.reloadRowData(id);
                            } else {
                                modals.hideWin(winId);
                                trainTable.reloadData();
                            }
                        }
                    });
                });
            },
            fields: {
                "name": {
                    validators: {
                        notEmpty: {message: '课程名称不能为空'}
                    }
                },
                "courseTime": {
                    validators: {
                        notEmpty: {message: '上课时间不能为空'}
                    }
                },
                "duration": {
                    validators: {
                        notEmpty: {message: '课时不能为空'},
                        integer: {message: '请填写整数'}
                    }
                },
                "teacher": {
                    validators: {
                        notEmpty: {message: '上课老师不能为空'}
                    }
                },
                "address": {
                    validators: {
                        notEmpty: {message: '地点不能为空'}
                    }
                }
            }
        });
        //编辑回填
        //初始化控件
        trainform.initComponent();
        if (id != 0) {
            ajaxPost(basePath + "/train/get/" + id, null, function (data) {
                trainform.initFormData(data);
            })
        }


    });

</script>
